/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.amuthu.indicator;

import com.tictactec.ta.lib.MAType;
import org.amuthu.DataStore;
import org.amuthu.TalibMgr;

/**
 *
 * @author prabhu
 */
public abstract class StochasticIndicator extends AbstractIndicator
{
   private int kFastPeriod;
   private int kSlowPeriod;
   private int dSlowPeriod;

   private double[] kvalue;
   private double[] dvalue;

   public double getDvalue()
   {
      return roundDouble(dvalue[0], 2);
   }

   public double getKvalue()
   {
      return roundDouble(kvalue[0], 2);
   }

   public StochasticIndicator(DataStore dataStore, int kFastPeriod, int kSlowPeriod, int dSlowPeriod, int startOffset)
   {
      super(dataStore, startOffset);
      this.kFastPeriod = kFastPeriod;
      this.kSlowPeriod = kSlowPeriod;
      this.dSlowPeriod = dSlowPeriod;

      kvalue = new double[1];
      dvalue = new double[1];
   }

   public void doCalculate()
   {
      int lastIdx = getLastIndex();

      TalibMgr.getTalib().stoch(lastIdx,
                                lastIdx,
                                getDataStore().getHigh(),
                                getDataStore().getLow(),
                                getDataStore().getClose(),
                                kFastPeriod,
                                kSlowPeriod,
                                MAType.Sma,
                                dSlowPeriod,
                                MAType.Sma,
                                TalibMgr.getOutBeginIdx(),
                                TalibMgr.getOutNbElement(),
                                kvalue,
                                dvalue);
   }

   @Override
   public int getDayDependency()
   {
      return TalibMgr.getTalib().stochLookback(kFastPeriod, kSlowPeriod, MAType.Sma, dSlowPeriod, MAType.Sma) + startOffset;
   }

}
